package com.zsrt.java.day20161227.hzj;

import java.text.DecimalFormat;
import java.util.Arrays;

import org.junit.Test;

public class HongBao {

    public static void main(String[] args) {
		System.out.println(Arrays.toString(hb(10,10)));
	}
	public static double[] hb(int number,double price){
		double[] rates = new double[number];
		int sum=0;
		int count=0;
		int p =0;
		int p1=0;
		if(number>0 && price >0){
			double age =price/number;
			if(age<0.01){
				System.out.println("单个红包金额不可以低于0.01元");
				return rates;
			}else{
				System.out.println("抢红包lala------");
				if(number!=1){
					System.out.println("aaaa");
					rates = caculator(number,price);
					for(int i=0;i<rates.length;i++){
						DecimalFormat df = new DecimalFormat("0.00");
						String aa = df.format(price*rates[i]);
						System.out.println("第"+i+"个人抢到的红包为"+aa+"元");
					}
					
				}else{
					System.out.println("抢到红包啦------");
					System.out.println("你抢到的金额为"+price+"总共就一个");
					return rates;
				}
			}
		}else{
			System.out.println("人数或者金额不可为零");
			return rates;
		}
		return rates;
	}
	
	public static  double[] caculator(int number,double price){
		double[] a = new double[number];
		double[] a1 = new double[number];
		int len = a.length;
		int len1 =a1.length;
		double sum=0;
		for(int i=0;i<len;i++){
			a[i]=Math.random()*price+0.01;
		//	System.out.println(a[i]);
			sum +=a[i];
		}
		for(int i=0;i<len1;i++){
			
			double sum1=0;
			double summ=0;
			DecimalFormat df = new DecimalFormat("0.00");
			double x = a[i]/sum;
			System.out.println(x+"aa"+i);
			String aa = df.format(x);
			a1[i] =Double.parseDouble(aa);
			sum1+=a1[i];
			summ =sum1;
			//System.out.println(sum1);
		
			//System.out.println(summ+=a1[i]);

			
			}
			
		return a1;	
		}
	
	}

